import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: '/',
        redirect: '/dashboard'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '首页'
                },
                component: () => import(
                    /* webpackChunkName: "dashboard" */
                    "../views/Dashboard.vue")
            }, {
                path: "/table",
                name: "basetable",
                meta: {
                    title: '表格'
                },
                component: () => import(
                    /* webpackChunkName: "table" */
                    "../views/BaseTable.vue")
            }, {
                path: "/charts",
                name: "basecharts",
                meta: {
                    title: '图表'
                },
                component: () => import(
                    /* webpackChunkName: "charts" */
                    "../views/BaseCharts.vue")
            }, {
                path: "/baseform",
                name: "baseform",
                meta: {
                    title: '公司信息'
                },
                component: () => import(
                    /* webpackChunkName: "form" */
                    "../views/website/BaseForm.vue")
            }, {
                path: "/tabs",
                name: "tabs",
                meta: {
                    title: 'tab标签'
                },
                component: () => import(
                    /* webpackChunkName: "tabs" */
                    "../views/Tabs.vue")
            }, {
                path: "/donate",
                name: "donate",
                meta: {
                    title: '鼓励作者'
                },
                component: () => import(
                    /* webpackChunkName: "donate" */
                    "../views/Donate.vue")
            }, {
                path: "/permission",
                name: "permission",
                meta: {
                    title: '权限管理',
                    permission: true
                },
                component: () => import(
                    /* webpackChunkName: "permission" */
                    "../views/Permission.vue")
            }, {
                path: "/i18n",
                name: "i18n",
                meta: {
                    title: '国际化语言'
                },
                component: () => import(
                    /* webpackChunkName: "i18n" */
                    "../views/I18n.vue")
            }, {
                path: "/upload",
                name: "upload",
                meta: {
                    title: '首页轮播'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/website/Upload.vue")
            },
            {
                path: "/testCase",
                name: "testCase",
                meta: {
                    title: '案例'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views//website/testCase.vue")
            },
            {
                path: "/planner",
                name: "planner",
                meta: {
                    title: '计划'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/website/Planner.vue")
            },
            {
                path: "/productcode",
                name: "productcode",
                meta: {
                    title: '产品'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/website/productcode.vue")
            },
            {
                path: "/service",
                name: "service",
                meta: {
                    title: '服务'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/website/Service.vue")
            },
            {
                path: "/resources",
                name: "resources",
                meta: {
                    title: '资源'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/website/Resources.vue")
            },
            {
                path: "/cooperation",
                name: "cooperation",
                meta: {
                    title: '合作伙伴'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/website/cooperation.vue")
            },
            // {
            //     path: "/filemtime",
            //     name: "filemtime",
            //     meta: {
            //         title: '文件'
            //     },
            //     component: () => import(
            //         /* webpackChunkName: "upload" */
            //         "../views/administrative/filemtime.vue")
            // },
            {
                path: "/Approval",
                name: "Approval",
                meta: {
                    title: '审批流程'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/Approval.vue")
            },
            {
                path: "/Financial",
                name: "Financial",
                meta: {
                    title: '报销付款'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/Management/Financial.vue")
            },
            // credentials
            {
                path: "/credentials",
                name: "credentials",
                meta: {
                    title: '汇款凭证'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/Management/credentials.vue")
            },
            {
                path: "/moneylosing",
                name: "moneylosing",
                meta: {
                    title: '用款支付'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/Management/moneylosing.vue")
            },
            {
                path: "/template",
                name: "template",
                meta: {
                    title: '文档'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/template.vue")
            },


            {
                path: "/expense",
                name: "expense",
                meta: {
                    title: '报销'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/expense.vue")
            },

            {
                path: "/system",
                name: "system",
                meta: {
                    title: '公司制度'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/System.vue")
            },
            {
                path: "/applymoney",
                name: "applymoney",
                meta: {
                    title: '用款申请单'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/applymoney.vue")
            },
            {
                path: "/procurement",
                name: "procurement",
                meta: {
                    title: '采购申请'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/procurement.vue")
            },
            {
                path: "/assets",
                name: "assets",
                meta: {
                    title: '固定资产'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/administrative/assets.vue")
            },
            {
                path: "/archives",
                name: "archives",
                meta: {
                    title: '个人信息'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/personnel/archives.vue")
            },
            {
                path: "/AssessmentIfc",
                name: "AssessmentIfc",
                meta: {
                    title: '考核档案'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/personnel/AssessmentIfc.vue")
            },
            {
                path: "/assessment",
                name: "assessment",
                meta: {
                    title: '业绩考核'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/personnel/assessment.vue")
            },
            {
                path: "/tutorial",
                name: "tutorial",
                meta: {
                    title: '项目清单'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/projects/tutorial.vue")
            },
            {
                path: "/libarchive",
                name: "libarchive",
                meta: {
                    title: '研发归档'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/projects/libarchive.vue")
            },
            {
                path: "/ProductService",
                name: "ProductService",
                meta: {
                    title: '物料信息'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/ProductService.vue")
            },
            {
                path: "/Warehouse",
                name: "Warehouse",
                meta: {
                    title: '仓库管理'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/Warehouse.vue")
            },
            {
                path: "/claimed",
                name: "claimed",
                meta: {
                    title: '配料'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/claimed.vue")
            },
            {
                path: "/picking",
                name: "picking",
                meta: {
                    title: '领料'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/picking.vue")
            },
            {
                path: "/inventory",
                name: "inventory",
                meta: {
                    title: '入库'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/inventory.vue")
            },
            {
                path: "/outbound",
                name: "outbound",
                meta: {
                    title: '出库'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/outbound.vue")
            },
            {
                path: "/product",
                name: "product",
                meta: {
                    title: '产品信息'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/product.vue")
            },
            {
                path: "/problem",
                name: "problem",
                meta: {
                    title: '生产反馈'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/problem.vue")
            },
            {
                path: "/supplier",
                name: "supplier",
                meta: {
                    title: '供应商管理'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/production/supplier.vue")
            },
            {
                path: "/current",
                name: "current",
                meta: {
                    title: '文档模版'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/resources/current.vue")
            },
            {
                path: "/maintenance",
                name: "maintenance",
                meta: {
                    title: '维修记录档案'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/aftersales/maintenance.vue")
            },
            {
                path: "/feedback",
                name: "feedback",
                meta: {
                    title: '用户反馈'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/aftersales/feedback.vue")
            },
            {
                path: "/Diagnosisb",
                name: "Diagnosisb",
                meta: {
                    title: '维修报告'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/aftersales/Diagnosisb.vue")
            },
            {
                path: "/visitors",
                name: "visitors",
                meta: {
                    title: '满意度调查'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/aftersales/visitors.vue")
            },
            {
                path: "/research",
                name: "research",
                meta: {
                    title: '调研报告'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/research.vue")
            },
            {
                path: "/warranty",
                name: "warranty",
                meta: {
                    title: '质保期'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/aftersales/warranty.vue")
            },
            {
                path: "/invoices",
                name: "invoices",
                meta: {
                    title: '发票管理'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/invoices.vue")
            },
            {
                path: "/salesstats",
                name: "salesstats",
                meta: {
                    title: '销售报备'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/salesstats.vue")
            },
            {
                path: "/authorization",
                name: "authorization",
                meta: {
                    title: '经销授权'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/authorization.vue")
            },
            {
                path: "/weekly",
                name: "weekly",
                meta: {
                    title: '销售周报'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/weekly.vue")
            },
            {
                path: "/opp",
                name: "opp",
                meta: {
                    title: '销售OPP'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/opp.vue")
            },
            {
                path: "/ufeedback",
                name: "ufeedback",
                meta: {
                    title: '起草合同'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/ufeedback.vue")
            },
            {
                path: "/Contractfile",
                name: "Contractfile",
                meta: {
                    title: '合同档案'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/Contractfile.vue")
            },
            {
                path: "/contracttabe",
                name: "contracttabe",
                meta: {
                    title: '合同汇总表'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/contracttabe.vue")
            },
            {
                path: "/tenderid",
                name: "tenderid",
                meta: {
                    title: '标书'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/tenderid.vue")
            },
            {
                path: "/winningtriple",
                name: "winningtriple",
                meta: {
                    title: '中标通知书'
                },
                component: () => import(
                    /* webpackChunkName: "upload" */
                    "../views/salesPerson/winningtriple.vue")
            },
            {
                path: "/user",
                name: "user",
                meta: {
                    title: '用户管理'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/user.vue")
            },
            {
                path: "/logdev",
                name: "logdev",
                meta: {
                    title: '系统日志'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/logdev.vue")
            },
            {
                path: "/personal",
                name: "personal",
                meta: {
                    title: '个人信息'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/personal.vue")
            },
            {
                path: "/role",
                name: "role",
                meta: {
                    title: '角色管理'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/system/role.vue")
            },
            {
                path: "/dictionary",
                name: "dictionary",
                meta: {
                    title: '字典管理'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/system/dictionary.vue")
            },
            {
                path: "/menu",
                name: "menu",
                meta: {
                    title: '菜单管理'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/system/menu.vue")
            },
            {
                path: "/menu",
                name: "menu",
                meta: {
                    title: '菜单管理'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/system/menu.vue")
            },
            {
                path: "/Departments",
                name: "Departments",
                meta: {
                    title: '部门管理'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/system/Departments.vue")
            },
            {
                path: "/icon",
                name: "icon",
                meta: {
                    title: '自定义图标'
                },
                component: () => import(
                    /* webpackChunkName: "icon" */
                    "../views/Icon.vue")
            }, {
                path: '/404',
                name: '404',
                meta: {
                    title: '找不到页面'
                },
                component: () => import(/* webpackChunkName: "404" */
                    '../views/404.vue')
            }, {
                path: '/403',
                name: '403',
                meta: {
                    title: '没有权限'
                },
                component: () => import(/* webpackChunkName: "403" */
                    '../views/403.vue')
            }
        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import(
            /* webpackChunkName: "login" */
            "../views/Login.vue")
    }
];

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} -戬威后台`;
    const role = sessionStorage.getItem('ms_username');
    if (!role && to.path !== '/login') {
        next('/login');
    } else if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        role === 'admin'
            ? next()
            : next('/403');
    } else {
        next();
    }
});

export default router;